package com.maxd.respository.article;

import com.maxd.model.ArticleClassify;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface ArticleClassifyRepository extends Repository<ArticleClassify, Long> {


    @Query(value = "select * from article_classify where state=1 order by sort",nativeQuery = true)
    List<ArticleClassify> selectArticleClassifyList();

    @Transactional
    @Modifying
    @Query(value = "update article_classify set state=:state where id=:articleClassifyId",nativeQuery = true)
    Integer updateStateByArticleClassifyId(@Param("articleClassifyId") Long articleClassifyId, @Param("state") Integer state);

    @Transactional
    @Modifying
    @Query(value = "update article_classify set classify_name=:articleClassifyName where id=:articleClassifyId",nativeQuery = true)
    Integer updateClassifyNameByArticleClassifyId(@Param("articleClassifyId") Long articleClassifyId, @Param("articleClassifyName") String articleClassifyName);

    @Transactional
    @Modifying
    @Query(value = "update article_classify set sort=:sort where id=:articleClassifyId",nativeQuery = true)
    Integer updateSortByArticleClassifyId(@Param("articleClassifyId") Long articleClassifyId, @Param("sort") Integer sort);

}